

function documentMgtCtrl($scope, $http) {
  'ngInject';
  // 档案盒数据
  this.documentList = [];

  this.shouldTableShow = false;

  this.loadImage = function(image) {
    return require(`../../../assets/images/book-${image.checkCategoryID}.png`);
  };

  // 判断条件跳转到
  this.toDocumentItemMgt = (innerItem) => {
    $state.go('documentItemMgt', {
      id: innerItem.checkCategoryID,
      type: 'detail',
      role: innerItem.role,
    });
  }

  // 处理档案盒数据用于展示
  this.getDocumentList4show= () => {
    let step = 0;
    let index = 0;
    let result = [];
    this.documentList.forEach((item) => {
      if (step%5 == 0) {
      result.push([]);
    }
    index = result.length;
    step++;
    result[index-1].push(item);
  });
    return result;
  };

  this.selectRole = (role, $index) => {
    this.classifiedBoxes.forEach(item => item.active = false);
    role.active = true;
    this.documentList = role.boxes;;
    // 将原始数据变化为行展示内容
    this.documentList4show = this.getDocumentList4show();
  }

  // 初始化页面方法
  this.initDocumentMgtView = () => {
    $http
      .get(`${SERVER_CONTEXT}/api/documentBox/getDocumentBox`)
      .success((resp) => {
        resp[0].active = true;
        this.classifiedBoxes = resp;
        // 考核项数据加入$scope
        this.documentList = resp[0].boxes;;
        // 将原始数据变化为行展示内容
        this.documentList4show = this.getDocumentList4show();
      });
  }
  // 初始化页面
  this.initDocumentMgtView();
}

export default documentMgtCtrl;